using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.SessionState;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using DTO;
using BLL;


public class Upload : IHttpHandler, IRequiresSessionState
{    
    public Upload()
    {
       
    }

    public bool IsReusable
    {
        get { return true; }
    }
    public void ProcessRequest(HttpContext context)
    {
        int id = 0;
        string dirUrl = ""; 
        if (!string.IsNullOrEmpty(context.Request.QueryString["ID"]))
        {
            int.TryParse(context.Request.QueryString["ID"], out id);
        }
        if (id > 0)
        {
            dirUrl = Globals.ApplicationPath + "Upload/Thuvienhinhanh/" + id + "/";
            //dirUrl = context.Request.ApplicationPath + "/Upload/Thuvienhinhanh/" + id + "/";
            //dSystem.Windows.Forms.MessageBox.Show(dirUrl);
            if (context.Request.Files.Count > 0)
            {
                for (int j = 0; j < context.Request.Files.Count; j++)
                {
                    HttpPostedFile uploadFile = context.Request.Files[j];
                    if (uploadFile.ContentLength > 0)
                    {
                        uploadFile.SaveAs(context.Server.MapPath(dirUrl + uploadFile.FileName));
                        //byte[] fileData = new byte[uploadFile.ContentLength];
                        //uploadFile.InputStream.Read(fileData, 0, (int)fileData.Length);
                        //clsUser.AddFile(Convert.ToString(uploadFile.FileName.Substring(0,uploadFile.FileName.Length-4)),Convert.ToString(""),fileData,0,albumId);
                    }
                }
            }
        }
    }

}
